<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

class ps_robokassa {

    var $classname = "ps_robokassa";
    var $payment_code = "Rk";

function show_configuration() {
        global $VM_LANG;
        $db = new ps_DB();
        include_once(CLASSPATH ."payment/".$this->classname.".cfg.php"); // Read current Configuration

    ?>
<table>

        <tr>
                <td><strong>Test Mode</strong></td>
                <td>
                        <select name="LMI_MODE" class="inputbox" >
                                <option <?php if (@LMI_MODE == '1') echo "selected=\"selected\""; ?> value="1"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES') ?></option>
                                <option <?php if (@LMI_MODE != '1') echo "selected=\"selected\""; ?> value="0"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO') ?></option>
                        </select>
                </td>
                <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_AUTORIZENET_TESTMODE_EXPLAIN') ?></td>
        </tr>

        <tr>
                <td><strong>Почтовый адресс</strong></td>
                <td><input type="text" name="ROBOKASSA_EMAIL" class="inputbox" value="<?  echo ROBOKASSA_EMAIL ?>" /></td>
                <td>E-mail указанный в Robokassa</td>
        </tr>

        <tr>
                <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYMENT_ORDERSTATUS_SUCC') ?></strong></td>
                <td>
                        <select name="ROBOKASSA_VERIFIED_STATUS" class="inputbox" >
                        <?php
                                $q = "SELECT order_status_name,order_status_code FROM #__{vm}_order_status ORDER BY list_order";
                                $db->query($q);
                                $order_status_code = Array();
                                $order_status_name = Array();

                                while ($db->next_record()) {
                                        $order_status_code[] = $db->f("order_status_code");
                                        $order_status_name[] = $db->f("order_status_name");
                                }

                                for ($i = 0; $i < sizeof($order_status_code); $i++) {
                                        echo "<option value=\"" . $order_status_code[$i];
                                        if (ROBOKASSA_VERIFIED_STATUS == $order_status_code[$i])
                                                echo "\" selected=\"selected\">";
                                        else
                                                echo "\">";
                                                echo $order_status_name[$i] . "</option>\n";
                                }?>
                        </select>
                </td>
                <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYMENT_ORDERSTATUS_SUCC_EXPLAIN') ?></td>
        </tr>

        <tr>
                <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYMENT_ORDERSTATUS_FAIL') ?></strong></td>
                <td>
                        <select name="ROBOKASSA_INVALID_STATUS" class="inputbox" >
                        <?php
                                for ($i = 0; $i < sizeof($order_status_code); $i++) {
                                        echo "<option value=\"" . $order_status_code[$i];
                                        if (ROBOKASSA_INVALID_STATUS == $order_status_code[$i])
                                                echo "\" selected=\"selected\">";
                                        else
                                                echo "\">";
                                                echo $order_status_name[$i] . "</option>\n";
                        } ?>
                        </select>
                </td>
                <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYMENT_ORDERSTATUS_FAIL_EXPLAIN') ?></td>
        </tr>
        <tr>
                <td><strong>Site Address</strong></td>
                <td><input type="text" name="ROBOKASSA_CURRENT_SITE" class="inputbox" value="<?  echo ROBOKASSA_CURRENT_SITE ?>" /></td>
                <td>например - http://www.myWebShop.com/</td>
        </tr>
        <tr>
                <td><strong>Описание платежа</strong></td>
                <td><input type="text" name="LMI_PAYMENT_DESC" class="inputbox" value="<?  echo LMI_PAYMENT_DESC ?>" /></td>
                <td>для распечатке в платеже ROBOKASSA</td>
        </tr>

</table>
<?php
}

function has_configuration() {
        // return false if there's no configuration
        return true;
}

  /**
        * Returns the "is_writeable" status of the configuration file
        * @param void
        * @returns boolean True when the configuration file is writeable, false when not
        */
function configfile_writeable() {
        return is_writeable( CLASSPATH."payment/".$this->classname.".cfg.php" );
}

  /**
        * Returns the "is_readable" status of the configuration file
        * @param void
        * @returns boolean True when the configuration file is writeable, false when not
        */
function configfile_readable() {
        return is_readable( CLASSPATH."payment/".$this->classname.".cfg.php" );
}

  /**
        * Writes the configuration file for this payment method
        * @param array An array of objects
        * @returns boolean True when writing was successful
        */
function write_configuration( &$d ) {
        $my_config_array = array(        "LMI_MODE"                                         => $d['LMI_MODE'],
                                                                "ROBOKASSA_EMAIL"                         => $d['ROBOKASSA_EMAIL'],
                                                                "ROBOKASSA_VERIFIED_STATUS"         => $d['ROBOKASSA_VERIFIED_STATUS'],
                                                                "ROBOKASSA_INVALID_STATUS"        => $d['ROBOKASSA_INVALID_STATUS'],
                                                                "ROBOKASSA_PENDING_STATUS"        => $d['ROBOKASSA_PENDING_STATUS'],
                                                                "ROBOKASSA_CURRENT_SITE"                => $d['ROBOKASSA_CURRENT_SITE'],
                                                                "LMI_PAYMENT_DESC"                        => $d['LMI_PAYMENT_DESC'],
                            );
        $config = "<?php\n";
        $config .= "if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); \n\n";
        foreach( $my_config_array as $key => $value ) {
                $config .= "define ('$key', '$value');\n";
        }
        $config .= "?>";

        if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) {
                fputs($fp, $config, strlen($config));
                fclose ($fp);
                return true;
        }
        else
                return false;
}

  /**************************************************************************
  ** name: process_payment()
  ** returns:
  ***************************************************************************/
function process_payment($order_number, $order_total, &$d) {
      return true;
    }

}
